package com.cs.dingdingauto

import android.content.Context
import android.content.Intent
import android.util.Log
import androidx.work.*
import kotlinx.coroutines.delay

/**
 * @author liguandong
 * @data 2023/7/4
 *
 */
class LaunchAppWork2(val appContext: Context, workerParams: WorkerParameters) : CoroutineWorker(appContext, workerParams) {
    override suspend fun doWork(): Result {
        Log.i("lgd", "doWork: LaunchAppWork")
        var time = 8
        while (time > 0 && !AppUtils.isAppForeground(appContext)){
            Log.i("lgd", "doWork: LaunchAppWork retryTime ${time}")
            DingDingHelper.launchApp(appContext.packageName)
            delay(10000L)
            time--
        }
        return Result.success()
    }
}